const app = getApp()
Page({
  data: {
    islogin: false,
    loading: true,
    page: 0,
    category: [],
    company:[],
  },
  //生命周期函数--监听页面加载
  onLoad: function () {
    this.getApi();
  },
  /**
 * 生命周期函数--监听页面显示
 */
  onShow: function () {
    this.setData({
      islogin: !app.util().isNull(app.globalData.loginuser),
    })
  },
  //上拉加载
  onReachBottom: function () {
    var that = this;
    that.setData({
      loading: true,
    });
    that.getApi();
  },
  //获取API
  getApi: function () {
    let that = this;
    if (that.data.loading) {
      var parms = {
        page: that.data.page + 1
      }
      app.api().Get('api/v1/bestbao/category/index', parms, function (result) {
        if (result.code == 200) {
          var category = that.data.category;
          for (let i in result.data) {
            category.push(result.data[i]);
          }
          that.setData({
            category: category,
            page: parms.page,
          });
        }
      })
      that.setData({
        loading: false,
      });
    }
  },
  //电话预约
  onCall: function (e) {
    app.callPhone(e);
  },  
  //扫码
  onScan: function () {
    wx.scanCode({
      success(res) {
        if (res.errMsg == 'scanCode:ok') {
          wx.navigateTo({
            url: 'repair/create?code='+res.result
          })
        }else{
          wx.showModal({
            content: '扫码失败',
            showCancel: false
          }) 
        }
      },
      fail(res) {
        wx.showModal({
          content: '扫码失败',
          showCancel:false
        }) 
      },
    })
  },
  //搜索
  onSearch: function () {
    wx.navigateTo({
      url: 'repair/create',
    })
  }
})